#include "stdafx.h"
#include "tiles_pool.h"
#include "game_engine/director.h"
#include "PlayScene.h"
#include "game_path.h"

HGE *hge = 0;

bool FrameFunc()
{
    if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;

    CDirector::Instance().Update();
    return false;
}

bool RenderFunc()
{
    hge->Gfx_BeginScene();
    hge->Gfx_Clear(0);
    CDirector::Instance().Render();
    hge->Gfx_EndScene();
    return false;
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    hge = hgeCreate(HGE_VERSION);
    hge->System_SetState(HGE_FPS, 60);
    hge->System_SetState(HGE_SHOWSPLASH, false);
    hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
    hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
    hge->System_SetState(HGE_TITLE, "Hecate Edit");
    hge->System_SetState(HGE_WINDOWED, true);
    hge->System_SetState(HGE_FPS, HGEFPS_VSYNC);

    CString cstrTilesXMLPath = game_path::getGameXMLPath();
    cstrTilesXMLPath += L"tilesinfo.xml";

    if(hge->System_Initiate())
    {
        tiles_pool::Instance().init(hge, cstrTilesXMLPath);
        CDirector::Instance().PlayScene(new CPlayeScene());
        hge->System_Start();

        CDirector::Destroy();
    }
    else
    {
        ::MessageBox(NULL,
            CA2W(hge->System_GetErrorMessage()).m_psz,
            L"Error",
            MB_OK | MB_ICONERROR | MB_APPLMODAL);
    }

    hge->System_Shutdown();
    hge->Release();
    return 0;
}